package com.example.fitnessservice.module.dao.courseMapper;

import com.example.fitnessservice.module.pojo.CourseApply;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author feng
 * @version 1.0
 * @&#064;description: TODO
 * @&#064;date 2022/11/27 20:47
 */
@Mapper
public interface CourseApplyMapper {
    @Insert("insert into course_apply (apply_time,apply_user_id,apply_reason,apply_coach_id,apply_course_id,apply_if_already) " +
            "values " +
            "(#{applyTime},#{applyUserId},#{applyReason},#{applyCoachId},#{applyCourseId},#{applyIfAlready})")
    Integer submitApplication(CourseApply apply);

    @Select("select * from course_apply where apply_coach_id=#{coachId} and apply_if_already=0")
    List<CourseApply> getAllApppy(Integer coachId);

    @Update("update course_apply set apply_if_already=#{applyIfAlready} where apply_user_id=#{applyUserId} and apply_coach_id=#{applyCoachId} and apply_course_id=#{applyCourseId}")
    Integer approve(CourseApply courseApply);

    @Select("select * from course_apply where apply_user_id=#{userId} and apply_if_already=#{status}")
    List<CourseApply> getPersonalApplyStatus(@Param("userId") Integer userId, @Param("status") Integer applyStatus);

    @Select("select * from course_apply where id=#{applyId}")
    CourseApply getOneApplyById(Integer applyId);
@Update("update course_apply set apply_if_already=3 where id=#{applyId}")
    Integer updateApplyStatus(Integer applyId);
    /*写错了注解返回的行数会异常

     */
}
